/**
 * Created by on 2018/5/4.
 */
define(function () {

    var self,
        app = win.app,
        searchData = {
            keyword: ''
        }
    ;
    // orderSubmitArg

    var List = app.Module.extend({

        init: function () {
            self = this;
            self._super({
                _tag: 'p_list', // key, 对象放进pageModule
                _refreshAutoInit: true //自动加载刷新控件
            }, win);
            //orderSubmitArg = app.pageParameters['listadd_page'];
        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scroll1'];
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat153/getGwbgPage",
                xdata: {
                    page:goods.page+1,
                    limit: goods.limit,
                    keyword: searchData.keyword
                },
                cb: function (result) {
                    if (result.ok) {

                        //严重错误
                        //goods.data.length = 0;

                        var data = result.data;
                        goods.data.pushArray(data.data, goods.page == 0);

                        _super({
                            obj: goods,
                            dataLen: data.data.length,
                            nodata: '无商机主题信息...'
                        });
                    }
                }
            });
        },
        _search:function (data) {
            searchData.keyword = data.keyword.trim();
            self._refresh();
        },
        _lazy: function () {
            this._super();
            app.taps.call(win, [
                {
                    o: 'addBtn',
                    cb: function (e) {
                        app.openPage({
                            src: "gwat153/gwat153-add.html",
                            argsKey: 'listadd_page',
                            args: {
                                type: "sj-empty",
                                cb: function (obj) {
                                    self._refresh();
                                }
                            }
                        });
                    }
                }
            ]);
        },
        _ready: function () {


            Vue.component('gwat153item', {
                template: app.getByid(doc, 'gwat153item-template'),
                props: {
                    model: Array
                },
                methods: {
                    select: function (v) {
                        app.openPage({
                            src: "gwat153/gwat153-add.html",
                            argsKey: 'listadd_page',
                            args: {
                                type: "sj-info",
                                item: v,
                                cb: function (obj) {
                                    self._refresh();
                                }
                            }
                        });
                    },
                    deleteDetail: function (v, elobj) {
                        var vue = this;
                        app.confirm({
                            msg: '是否删除？',
                            ok: function () {
                                app.ajax({
                                    xurl: "api/wx/gwat153/checkTheme",
                                    loading: true,
                                    xdata: {
                                        GWBHNAME: v.GWBGL001,
                                        GWBHID: v.GWBG002
                                    },
                                    cb: function (result) {
                                        if (result.ok) {
                                            var count = result.data.count;
                                            if (count > 0) {
                                                app.alert({
                                                    msg: '拜访记录已经存在，无法删除'
                                                });
                                            } else {
                                                app.ajax({
                                                    xurl:"api/wx/gwat153/deleteTheme",
                                                    loading:true,
                                                    xdata:{
                                                        GWBE001:v.GWBGL001
                                                    },
                                                    cb:function (result) {
                                                        if(result.ok){

                                                            app.alert({
                                                                msg:'删除成功！',
                                                                ok:function () {
                                                                    self._refresh();
                                                                }
                                                            });

                                                        }
                                                    }
                                                })
                                            }
                                        }
                                    }
                                })
                            }
                        });

                    }
                }
            });
        }
    });

    return new List();

});